package com.winsdom.controller;

import com.winsdom.anno.Authentication;
import com.winsdom.dto.contract.AddContractDto;
import com.winsdom.dto.contract.ContractDto;
import com.winsdom.dto.contract.ExpenditureDto;
import com.winsdom.result.Result;
import com.winsdom.service.IContractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import static com.winsdom.enums.AuthenticationType.CONTRACT_MANAGEMENT;


@RestController
@RequestMapping("/contract")
@Api(tags = "合同管理相关接口")
@Authentication(value = CONTRACT_MANAGEMENT)
public class ContractController {

    @Autowired
    private IContractService contractService;

    @PostMapping("/list")
    @ApiOperation("根据参数获取合同列表")
    public Result getContractList(@RequestBody ContractDto contractDto) {
        return contractService.getContractList(contractDto);
    }

    @GetMapping("/detail/{contractId}")
    @ApiOperation("根据合同id获取合同详情")
    public Result getContractDetail(@PathVariable("contractId") Long contractId) {
        Result result = contractService.getContractDetail(contractId);
        return result;
    }

    @GetMapping("/invalid/{contractId}")
    @ApiOperation("作废合同")
    public Result invalidContract(@PathVariable("contractId") Long contractId) {
        Result result = contractService.invalidContract(contractId);
        return result;
    }


    @GetMapping("/get/list")
    @ApiOperation("获取客户列表还有分类表的树形结构")
    public Result getCustomerList() {
        return contractService.getList();
    }

    @PostMapping("/get/expenditure/list")
    @ApiOperation("获取费项列表，可以根据参数查询")
    public Result getExpenditureList(@RequestBody ExpenditureDto expenditureDto) {
        return contractService.getExpenditureList(expenditureDto);
    }

    @GetMapping("/get/feeFormula/list/{expenditureId}/{type}")
    @ApiOperation("根据费项ID-获取费项公式或者价格")
    public Result getFeeFormulaList(@PathVariable("expenditureId") Integer expenditureId,@PathVariable("type") Integer type){
        Result result= contractService.getFeeFormulaList(expenditureId,type);
        return result;
    }

    @GetMapping("/get/threeTables/{expenditureId}/{categoryId}")
    @ApiOperation("根据费项ID,资源ID获取三表信息")
    public Result getThreeTables(@PathVariable("expenditureId") Integer expenditureId,@PathVariable("categoryId") Long categoryId){
        Result result= contractService.getThreeTables(expenditureId,categoryId);
        return result;
    }

    @PostMapping("/add")
    @ApiOperation("添加合同")
    public Result addContract(@RequestBody AddContractDto contractDto) {
        Result result = contractService.addContract(contractDto);
        return result;
    }

    @PostMapping("/update")
    @ApiOperation("修改合同")
    public Result updateContract(@RequestBody AddContractDto contractDto) {
        Result result = contractService.updateContract(contractDto);
        return result;
    }
}
